package com.hq.ims.data.service;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.hq.ims.data.config.verification.VdAdd;
import com.hq.ims.data.config.verification.VdEdit;
import com.hq.ims.data.dao.BusiRepeatTypeCountMapper;
import com.hq.ims.data.entity.BusiRepeatTypeCount;
import com.hq.ims.data.vo.BusiRepeatTypeCountMapstruct;
import com.hq.mybatis.base.BaseService;
import com.hq.mybatis.base.page.RequestPage;
import com.hq.utils.util.ObjectUtils;
import com.hq.web.utils.SpringBootValidateUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * @author 蒋柏平
 * @since 20241025
 * @detail 经营信息重复类型数量表 服务实现类
 */
@Service
public class BaseBusiRepeatTypeCountService extends BaseService<BusiRepeatTypeCountMapper, BusiRepeatTypeCount> {


    /**
    * 分页
    */
    public List<BusiRepeatTypeCountMapstruct.BusiRepeatTypeCountVo> getByPage(
            RequestPage page,
            BusiRepeatTypeCountMapstruct.PageSearchVo searchVo
    ) {
        //验证
        LambdaQueryChainWrapper<BusiRepeatTypeCount> lq = this.lambdaQuery();
        //排序
        //查询条件

        //执行分页
        lq.page(page);

        List<BusiRepeatTypeCount> dataList = page.getRecords();
        List<BusiRepeatTypeCountMapstruct.BusiRepeatTypeCountVo> voList = BusiRepeatTypeCountMapstruct.INSTANCE.toBusiRepeatTypeCountVoList(dataList);
        page.setRecords(voList);
        return voList;
    }

    /**
      * 添加
      */
    @Transactional(rollbackFor = Exception.class)
    public BusiRepeatTypeCount addData(BusiRepeatTypeCountMapstruct.SaveVo vo) {
        //验证
        SpringBootValidateUtils.validate(vo,VdAdd.class);

        //账值新的对象
        BusiRepeatTypeCount entity = new BusiRepeatTypeCount();
        entity.setRepeatType(vo.getRepeatType());
        entity.setRepeatCount(vo.getRepeatCount());
        entity.setBusiInfoId(vo.getBusiInfoId());
        entity.setMaxSimilarityRate(vo.getMaxSimilarityRate());

        entity.insert();
        return entity;
    }

     /**
     * 编辑
     */
     @Transactional(rollbackFor = Exception.class)
     public BusiRepeatTypeCount editData(BusiRepeatTypeCountMapstruct.SaveVo vo) {
         //验证
        SpringBootValidateUtils.validate(vo,VdEdit.class);

        //账值新的对象
        BusiRepeatTypeCount entity = this.getById(vo.getBusiRepeatTypeCountId());
        ObjectUtils.isNullThrow(entity, "数据不存在");

        entity.setRepeatType(vo.getRepeatType());
        entity.setRepeatCount(vo.getRepeatCount());
        entity.setBusiInfoId(vo.getBusiInfoId());
        entity.setMaxSimilarityRate(vo.getMaxSimilarityRate());

        entity.updateById();
        return entity;
     }


    /**
    * 删除
    */
    @Transactional(rollbackFor = Exception.class)
    public void delByBusiRepeatTypeCountId(String busiRepeatTypeCountId) {
        BusiRepeatTypeCount data = this.getById(busiRepeatTypeCountId);
        if(data == null){
            return;
        }
        data.deleteById();
    }

    /**
     * 删除
     */
    @Transactional(rollbackFor = Exception.class)
    public void delByBusiId(String busiId) {
        this.lambdaUpdate().eq(BusiRepeatTypeCount::getBusiInfoId,busiId).remove();
    }

    /**
     * 获取原始数据详情
     */
    public BusiRepeatTypeCountMapstruct.BusiRepeatTypeCountVo getDetailVo(String busiRepeatTypeCountId) {
        BusiRepeatTypeCount entity = this.getById(busiRepeatTypeCountId);
        BusiRepeatTypeCountMapstruct.BusiRepeatTypeCountVo vo = BusiRepeatTypeCountMapstruct.INSTANCE.toBusiRepeatTypeCountVo(entity);
        return vo;
    }
}